package org.example.backend.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 假设你的外部图片存储在 /opt/images 目录下
        String imagePath = "file:/uploads/wallpaper/";

        // 将以 /images/ 开头的请求映射到 /opt/images 目录
        registry.addResourceHandler("/images/**")
                .addResourceLocations(imagePath);

        // 如果你的外部图片路径是相对于 Spring Boot 项目的某个目录，例如项目根目录下的 external-images 文件夹
        // String projectBasePath = System.getProperty("user.dir");
        // String relativeImagePath = "file:" + projectBasePath + "/external-images/";
        // registry.addResourceHandler("/external-images/**")
        //         .addResourceLocations(relativeImagePath);
    }
}